//PancakePuzzle Class

//Walter Lehner
//David Witwer

import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class PancakePuzzle implements StateSpace {

        int[] start;
        int[] goal;
        int PuzzleSize;

        public PancakePuzzle(int[] start, int[] goal) {
                this.start = start;
                this.goal = goal;
                PuzzleSize=goal.length;//clever
        }
//getKids seems good
        public Vector<State> getKids(State current) {
            Vector<State> kids = new Vector<State>();
            int[] c=current.getRep();
            int[] kid;
            State kidState;

            for(int i=1; i<=current.getNextBottom(); i++){
                kid=new int[c.length];
                for(int j=i; j>=0; j--){
                    kid[i-j]=c[j];
                }
                for(int j=i+1; j<c.length; j++){
                    kid[j]=c[j];
                }
                kidState=new State(current, kid);
                //System.out.println("Kid: "+kidState.toString()+"\tF = "+kidState.getF());
                if(!kids.contains(kidState)){
                    kids.add(kidState);
                }
            }
            return kids;
        }

        public int[] getGoal() {
              return goal;
        }

        public int[] getStart() {
              return start;
         }

        public boolean isGoal(int[] rep) {
              for(int i=0; i<rep.length; i++){
                  if(rep[i]!=goal[i]){
                      return false;
                  }
              }
              return true;
        }
}
